package club.ximeng.sliceupload.upload.dto;

import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author liu xm
 * @date 2022-03-08 9:22
 */
@Data
public class FileUploadParamDTO implements Serializable {

    /**
     * MultipartFile
     */
    private MultipartFile chunk;
    /**
     * 分片索引,例：0
     */
    @NotNull(message = "分片索引不能为空")
    private Integer chunkIndex;
    /**
     * 文件hash,例：fcb82c7992a27ba8500630b4930f0036
     */
    @Length(min = 32, max = 32,message = "文件hash不正确")
    @NotBlank(message = "文件hash不能为空")
    private String hash;

    /**
     * 获取chunk name,例：fcb82c7992a27ba8500630b4930f0036-0
     *
     * @return chunk name
     */
    public String chunkName() {
        return hash + "-" + chunkIndex;
    }
}
